package pms.db.contrl.action;

import java.util.List;

import pms.common.utils.PMSLog;
import pms.common.value.MasterManageValue;
import pms.common.value.ThemeValue;
import pms.db.contrl.service.MasterManageService;
import com.opensymphony.xwork2.ActionSupport;

public class MasterManageAction extends ActionSupport {
	
	private static final long serialVersionUID = 2276244620030684335L;
	private List<MasterManageValue> masterManageValueList;
	private MasterManageService masterManageService;
	private MasterManageValue addMasterManageValue;
	private String dbCode;
	private int addMode = 0;
	
	public MasterManageValue getAddMasterManageValue() {
		return addMasterManageValue;
	}
	public void setAddMasterManageValue(MasterManageValue addMasterManageValue) {
		this.addMasterManageValue = addMasterManageValue;
	}
	public int getAddMode() {
		return addMode;
	}
	public void setAddMode(int addMode) {
		this.addMode = addMode;
	}
	public String getDbCode() {
		return dbCode;
	}
	public void setDbCode(String dbCode) {
		this.dbCode = dbCode;
	}
	public MasterManageService getMasterManageService() {
		return masterManageService;
	}
	public void setMasterManageService(MasterManageService masterManageService) {
		this.masterManageService = masterManageService;
	}
	public List<MasterManageValue> getMasterManageValueList() {
		return masterManageValueList;
	}
	public void setMasterManageValueList(List<MasterManageValue> masterManageValueList) {
		this.masterManageValueList = masterManageValueList;
	}
	public String execute() {
		PMSLog.start();
		masterManageValueList = masterManageService.getMasterList();
		PMSLog.end();
		return SUCCESS;
	}
	public String doAdd() {
		PMSLog.start();
		if(null != addMasterManageValue) {
			masterManageService.doAdd(addMasterManageValue);
		}
		this.setAddMode(0);
		execute();
		PMSLog.end();
		return SUCCESS;
	}
	public String doUpdate() {
		PMSLog.start();
		for(MasterManageValue l_mmv : this.getMasterManageValueList()) {
			if(l_mmv.getDbCode().equals(this.getDbCode())) {
				masterManageService.doUpdate(l_mmv);
				break;
			}
		}
		execute();
		PMSLog.end();
		return SUCCESS;
	}
	public String doEdit() {
		PMSLog.start();
		execute();
		for(MasterManageValue l_mmv : masterManageValueList) {
			if(l_mmv.getDbCode().equals(this.getDbCode())) {
				l_mmv.setEditFlag(1);
				break;
			}
		}
		PMSLog.end();
		return SUCCESS;
	}
	public String doDelete() {
		PMSLog.start();
		for(MasterManageValue l_mmv : this.getMasterManageValueList()) {
			if(l_mmv.getDbCode().equals(this.getDbCode())) {
				masterManageService.doDelete(l_mmv);
				break;
			}
		}
		execute();
		PMSLog.end();
		return SUCCESS;
	}

}
